package mylibrary.httpcore;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import org.apache.http.Header;
import org.apache.http.HeaderIterator;
import org.apache.http.HttpConnection;
import org.apache.http.HttpConnectionMetrics;
import org.apache.http.HttpEntity;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.impl.DefaultBHttpClientConnection;
import org.apache.http.message.BasicHttpRequest;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.util.EntityUtils;

public class Test {

	public static void main(String[] args) throws Exception {
		
//		HttpRequest request = new BasicHttpRequest("GET", "http://www.163.com", HttpVersion.HTTP_1_1);
//		System.out.println(request.getRequestLine().getMethod());
//		System.out.println(request.getRequestLine().getUri());
//		System.out.println(request.getRequestLine().getProtocolVersion());
//		System.out.println(request.getRequestLine().toString());
		
//		HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
//		System.out.println(response.getProtocolVersion());
//		System.out.println(response.getStatusLine().getStatusCode());
//		System.out.println(response.getStatusLine().getReasonPhrase());
//		System.out.println(response.getStatusLine().toString());
		
//		response.addHeader("Set-Cookie", "c1=a; path=/; domain=localhost");
//		response.addHeader("Set-Cookie", "c2=b; path=\"/\", c3=c; domain=\"localhost\"");
//		Header header1 = response.getFirstHeader("Set-Cookie");
//		System.out.println(header1);
//		System.out.println(response.getLastHeader("Set-Cookie"));
//		Header[] headers = response.getHeaders("Set-Cookie");
//		Header[] allHeaders = response.getAllHeaders();
//		HeaderIterator it = response.headerIterator("Set-Cookie");
		
		
		
//		Socket socket = new Socket("172.30.65.144", 8090);
//		DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(8*1024);
//		conn.bind(socket);
//		System.out.println(conn.isOpen());
//		HttpConnectionMetrics metrics = conn.getMetrics();
//		System.out.println(metrics.getRequestCount());
//		System.out.println(metrics.getResponseCount());
//		System.out.println(metrics.getReceivedBytesCount());
//		System.out.println(metrics.getSentBytesCount());
		
		//can't work
//		Socket socket = new Socket("localhost", 8070);
//		DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(8*1024);
//		conn.bind(socket);
//		HttpRequest request = new BasicHttpRequest("GET", "/sample");
//		conn.sendRequestHeader(request);
//		HttpResponse response = conn.receiveResponseHeader();
//		conn.receiveResponseEntity(response);
//		HttpEntity entity = response.getEntity();
//		if(entity != null) {
//			EntityUtils.consume(entity);
//		}
	}
}
